Repository navigation
Conversation
briangow
force-pushed
the
bg_enable_seg_cohesion
branch
from
October 29, 2026 20:21
1257006 to
51faaf0
Compare
tompollard
reviewed
Oct 31, 2026
tompollard
left a comment
Member
There was a problem hiding this comment.
Thanks Brian, checking all the segments before writing anything is a good change. On main, a segment whose length doesn't match seg_len gets written without any error, and a bad segment partway through leaves half-written files. This PR fixes both.
I tried a few cases locally, and two writes that work on main are now rejected:
- The expanded check runs even when
expanded=False. A segment with a validd_signaland an out-of-datee_d_signalnow fails, even though onlyd_signalis written. The check also falls back toe_p_signal, which is never written. Could we passexpandedinto_check_segment_cohesionand only checke_d_signalwhen it'sTrue? samps_per_frame=[None]is rejected.Record.wrsamp(expanded=True)treats a missing value as 1 (check_sig_cohesionin_signal.py), so a segment that writes fine on its own now fails inside a multi-segment record. It would be good to treat it the same way here.
Both of these come from having the expanded-length rule in two places. Another option is to drop the new block and run each segment's existing checks (its header field checks plus check_sig_cohesion) in a first pass, then write everything in a second pass. That keeps the "check before writing" behaviour with a single rule.
A few smaller things:
- Gap segments (
None, e.g. from reading a variable-layout record withsampto) now fail with'NoneType' object has no attribute 'fs'. That isn't worse than before, but a clear error saying gap segments can't be written yet would help. - There are no tests for
MultiRecord.wrsampyet. It would be good to add:- a round trip of
041s - a
seg_lenmismatch - a bad segment after a good one, checking that no files are written
- the two cases above that should be accepted
- a round trip of
- Could you add a changelog entry to
docs/changes.rst? - A few of the new error message lines are over 88 characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As mentioned in #557, we should add segment validation when writing multi-segment records. This PR adds pre-write validation to
MultiRecord.wrsamp()by activating the previously unused_check_segment_cohesion()method, which is now called before any files are written.The validation includes checks for basic segment cohesion (matching
n_seg, sampling frequencies, and segment lengths) as well as new validation for expanded signals. For segments withe_d_signalore_p_signal, the method now verifies thatsamps_per_frameis properly set for all channels and that expanded signal lengths match expected values (samps_per_frame[ch] * sig_len). This provides clear, descriptive error messages when segments are misconfigured, preventing invalid multi-segment records from being written.